<?php

class Zend_View_Helper_ContentHelper extends Zend_View_Helper_Abstract {

    private $options = array(
    );
    private static $addsSession = null;

    public function __construct() {
        self::$addsSession = new Zend_Session_Namespace(Common_Controller_Main::ADDS_SESSION_NAME);
    }

    public function contentHelper($content, $options = null) {
        $ret = '';

        $options = !empty($options) ? array_merge($this->options, $options) : $this->options;

        if (!isset($content) || empty($content))
            return $ret;
        $html = '';

        foreach ($content as $item) {

            $ses = self::$addsSession->{'addId' . $item['id']};
            $html = '';

            $body = strip_tags($item['short'], Application_Model_Content::STRIP_TAGS);

            if (Application_Model_Content::TYP_EXTADD == $item['typ']) {
                $body = $item['short'];
            }

            if ($item['optionCheck'] == Application_Model_Content::OPT_HIDEADD_ONSESSION_CLICK && $ses != null)
                continue;
            $html = '<div id="' . (!empty($item['name']) ? $item['name'] : 'add' ) . '-' . $item['id'] . '" class="content-item' . (!empty($item['name']) ? ' ' . $item['name'] : '') . '">';
            $html .= '<div class="add-body">';
            $more = null;
            
            if ($item['addUrl'] != "") {
                $more = '<div class="add-more"><div class="add-more-wrap"><a href="'
                        . $this->view->url(array(
                            'module' => 'default', 'controller' => 'index', 'action' => array_search($item['typ'], array(Application_Model_Content::TYP_ADD, Application_Model_Content::TYP_EXTADD)) !== false ? 'add' : 'content', 'id' => $item['id'],
                                ), 'default', true)
                        . '" class="more-link">więcej</a></div></div>';
            }
            
            $html .= '<div class="add-body-content">' . preg_replace(array(
                '#\{more\}#',
                '#\{([^\/]+)\}#',
            ),array(
                $more,
                ''
            ),$body) . '</div>';
            $html .='</div>';





            $html .='</div>';

            $ret .= $html;
        }

        return $ret;
    }

}